#include <iostream>
#include <string>

class Calculate
{
public:
    virtual int getResult()
    {
        return 0;
    }    

    int m_Num1;
    int m_Num2;
};

class AddCalculate : public Calculate
{
public:
    int getResult()
    {
        return m_Num1 + m_Num2;
    }
};

class SubCalculate : public Calculate
{
public:
    int getResult()
    {
        return m_Num1 - m_Num2;
    }
};

class MulCalculate : public Calculate
{
public:
    int getResult()
    {
        return m_Num1 * m_Num2;
    }
};

class DivCalculate : public Calculate
{
public:
    int getResult()
    {
        return m_Num1 / m_Num2;
    }
};

void test01()
{
    // 多态使用条件
    // 1. 父类指针或引用指向子类对象
    // 好处：
    // 1. 代码组织结构清晰
    // 2. 代码可维护性高
    // 3. 代码可扩展性高
    // 加法
    Calculate *abc = new AddCalculate;
    abc->m_Num1 = 10;
    abc->m_Num2 = 20;
    std::cout << abc->m_Num1 << " + " << abc->m_Num2 << " = " << abc->getResult() << std::endl;
    delete abc;

    // 减法
    abc = new SubCalculate;
    abc->m_Num1 = 10;
    abc->m_Num2 = 20;
    std::cout << abc->m_Num1 << " - " << abc->m_Num2 << " = " << abc->getResult() << std::endl;
    delete abc;

    // 乘法
    abc = new MulCalculate;
    abc->m_Num1 = 10;
    abc->m_Num2 = 20;
    std::cout << abc->m_Num1 << " * " << abc->m_Num2 << " = " << abc->getResult() << std::endl;
    delete abc;

    // 除法
    abc = new DivCalculate;
    abc->m_Num1 = 10;
    abc->m_Num2 = 20;
    std::cout << abc->m_Num1 << " / " << abc->m_Num2 << " = " << abc->getResult() << std::endl;
    delete abc;
}

int main()
{
    test01();
    return 0;
}